def p(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

n = int(input())
l = [i for i in range(2, n+1) if p(i)]

m = 0
for i in l:
    if str(i) in str(n):
        m = i
print(m)